package com.website.main.controller;

import com.website.main.service.S_Role;
import com.website.mybatis.entity.SysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author ZSW
 *
 */
@Controller
@RequestMapping("admin/role")
public class C_Role {

	@Autowired
	S_Role role;

	/**
	 * 获取所有
	 * @return
	 */
	@RequestMapping("/getAll")
	@ResponseBody
	public Map<String,Object> getAll(){
		return role.getAllRoles();
	}
	/**
	 * 分页获取
	 * @return
	 */
	@RequestMapping("/getList")
	@ResponseBody
	public Map<String,Object> getList(String name,
			@RequestParam(defaultValue = "1")int page,
			@RequestParam(defaultValue = "-1")int limit){
		return role.getList(name,page,limit);
	}

	/**
	 * 添加
	 * @param r r
	 */
	@RequestMapping("/save")
	@ResponseBody
	public Map<String,Object> save(SysRole r){
		return role.save(r);
	}
	/**
	 * 删除
	 * @return
	 */
	@RequestMapping("/del")
	@ResponseBody
	public Map<String,Object> del(@RequestParam(required = true)Integer id){
		return role.delete(id);
	}
	/**
	 * 更新
	 * @return
	 */
	@RequestMapping("/upd")
	@ResponseBody
	public Map<String,Object> upd(SysRole user){
		return role.update(user);
	}

	/**更新权限
	 * @param user
	 * @return
	 */
	@RequestMapping("/updPowers")
	@ResponseBody
	public Map<String,Object> updPowers(Integer id, Integer[] powers){
		return role.updPowers(id, powers);
	}
}
